package com.tradeservices;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;

import com.domain.Trade;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;

@Path("/tradeService")
public class TradeService {

	@Path("/getTrade/{id}")
	@GET
	@Produces({ "application/json" })
	public String getTrades(@PathParam("id") Long id,
			@Context HttpHeaders headers) throws JsonProcessingException {
		Integer version = calculateAcceptVersion(headers.getAcceptableMediaTypes().get(0)
				.getParameters().get("version"));

		Trade trade = new Trade();

		ObjectMapper mapper = new ObjectMapper();
		
		
		FilterProvider fp = new VersionEntityFilterProvider(version );

		String json = mapper.writer(fp).writeValueAsString(trade);

		return json;
	}

	private Integer calculateAcceptVersion(String version) {
		return Integer.valueOf(version);
	}
}
